package com.hxs.hxsserver.controller.factor;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hxs.hxsserver.domain.dto.IdDTO;
import com.hxs.hxsserver.domain.dto.JsonResult;
import com.hxs.hxsserver.domain.dto.device.*;
import com.hxs.hxsserver.service.FactorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author liuchuan
 * @create 2024/9/27
 */
@Slf4j
@RestController
@Api(value = "因子管理")
@RequestMapping("factor")
public class FactorController {
    @Resource
    FactorService factorService;


    @PostMapping("/insertFactor")
    @ApiOperation(value = "新增因子")
    public JsonResult<Boolean> insertFactor(@RequestBody @Validated FactorDTO factorDTO){
        return JsonResult.success(factorService.insertFactor(factorDTO));
    }

    @PostMapping("/updateFactor")
    @ApiOperation(value = "编辑因子")
    public JsonResult<Boolean> updateFactor(@RequestBody @Validated FactorDTO factorDTO){
        return JsonResult.success(factorService.updateFactor(factorDTO));
    }

    @PostMapping("/deleteFactor")
    @ApiOperation(value = "删除因子")
    public JsonResult<Boolean> deleteFactor(@RequestBody @Validated IdDTO factorDTO){
        return JsonResult.success(factorService.deleteFactor(factorDTO));
    }

    @GetMapping("/getFactorById")
    @ApiOperation(value = "查看因子信息")
    public JsonResult<FactorDTO> getFactorById(@Validated IdDTO factorDTO){
        return JsonResult.success(factorService.getFactorById(factorDTO));
    }

    @GetMapping("/getFactorList")
    @ApiOperation(value = "获取因子列表")
    public JsonResult<IPage<FactorDTO>> getFactorList(@Validated QueryFactorListDTO factorDTO){
        return JsonResult.success(factorService.getFactorList(factorDTO));
    }

    @GetMapping("/getFactorHisLastList")
    @ApiOperation(value = "根据设备地址码获取最新的因子数据")
    public JsonResult<List<QueryFactorHisLastList>> getFactorHisLastList(@Param("deviceHardwareAddr") String deviceHardwareAddr){
        return JsonResult.success(factorService.getFactorHisLastList(deviceHardwareAddr));
    }

    @GetMapping("/getFactorHisListByNodeno")
    @ApiOperation(value = "根据设备地址获取因子历史信息")
    public JsonResult<IPage<ReturnFactorHis>> getFactorHisListByNodeno(QueryFactorHisDTO queryFactorHisDTO){
        return JsonResult.success(factorService.getFactorHisListByNodeno(queryFactorHisDTO));
    }
}
